package com.acwing.partition13;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/6 10:10
 */
public class AC1222密码脱落 {

    private static final int N = 1010;
    private static String s;
    private static int[][] f = new int[N][N];
    private static int n;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        s = reader.readLine();
        n = s.length();
        for (int i = 0; i < n; i++) f[i][i] = 1;
        for (int len = 2; len <= n; len++) {
            for (int i = 0; i + len - 1 < n; i++) {
                int j = i + len - 1;
                if (s.charAt(i) == s.charAt(j)) f[i][j] = f[i + 1][j - 1] + 2;
                if (f[i][j - 1] > f[i][j]) f[i][j] = f[i][j - 1];
                if (f[i + 1][j] > f[i][j]) f[i][j] = f[i + 1][j];
            }
        }
        writer.write((n - f[0][n - 1]) + "\n");
        writer.flush();
    }
}
